//
//  ThreeViewController.m
//  PeiJue
//
//  Created by lxy on 2017/12/11.
//  Copyright © 2017年 lixiya. All rights reserved.
//

#import "ThreeViewController.h"
#import "XYAtttributeLabel.h"

@interface ThreeViewController ()<XYAtttributeLabelDeleagte>

@property(nonatomic, assign) NSRange range;

@end

@implementation ThreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.range.length == 0) {
        NSLog(@"00000");
    }else{
        NSLog(@"11111");
    }
    
    
    XYAtttributeLabel *label = [[XYAtttributeLabel alloc] init];
    label.delegate = self;
    label.frame = CGRectMake(0, 100, self.view.frame.size.width, 400);
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    [self.view addSubview:label];
    
    NSString *text = @"小李回复小明:小明16种常见蔬菜的挑选窍门，@菜贩再也蒙不了你了！ ​​​​#美食#  你还相信大神吗?“区块链培训”需求爆增9倍 培训班鱼龙混杂、3天产出80个讲师http://t.cn/RE6vjZj】 。从去年年末至今，大企业也纷纷试水区块链课程/内容：网易科技上线付费课程，首档推出区块链公开课；百度经验推出《区块链100问》 短视频；腾讯课堂也上线了区块链或数字货币相关课程。此外36氪、...全文： http://m.weibo.cn/2341202571/4212783400546899";
    
    [label setAttributedText:[[NSAttributedString alloc] initWithString:text]];
    
    NSRange range = [text rangeOfString:@"小明"];
    NSLog(@"---%@",NSStringFromRange(range));
    
    [label addCustomLinkWithString:@"小李" linkRange:NSMakeRange(0, 2)];
    [label addCustomLinkWithString:@"小明" linkRange:NSMakeRange(4, 2)];

}

- (void)atttributeLabel:(XYAtttributeLabel *)label didSelectedLinkText:(NSString *)linkText linkRange:(NSRange)linkRange linkType:(XYAtttributeLabelLinkType)linkType {
    NSLog(@"代理回调--%@  %@",linkText,NSStringFromRange(linkRange));
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
